<template>
  <div>
    <select v-model="contents">
      <option
        v-for="(item, index) in content_list"
        :key="index"
        :value="item.title"
      >
        {{ item.title }}
      </option>
    </select>
    <button @click="add_task">发布学习任务</button>

    <br /><br />

    <table>
      <tr>
        <td>学生名称</td>
        <td>学习任务</td>
        <td>开始时间</td>
        <td>完成时间</td>
        <td>完成时长(秒)</td>
        <td>完成状态</td>
      </tr>
      <tr v-for="(item, index) in records_list" :key="index">
        <td>{{ item.user_account }}</td>
        <td>{{ item.task }}</td>
        <td>{{ datetime(item.start_time) }}</td>
        <td>{{ datetime(item.finish_time) }}</td>
        <td>{{ item.tokinaga }}</td>
        <td>{{ item.is_status }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
import { datetime } from "../utils/utils";
export default {
  data() {
    return {
      datetime,
      records_list: "",
      user_id: localStorage.getItem("id"),

      contents:'',
      content_list:'',
      clbums:'',
      clbum_list:'',
    };
  },
  mounted() {
    this.record_show();
    this.content_show();
  },
  methods: {
    record_show: function () {
      this.myaxios(this.host + "study/records/", "get", {
        user_id: this.user_id,
      }).then((data) => {
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.records_list = data.data;
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
    content_show: function(){
      this.myaxios(this.host + "study/contents/", "get", {
        user_id: this.user_id,
      }).then((data) => {
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.content_list = data.data;
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
    add_task: function(){
      this.myaxios(this.host + "study/tasks/", "post", {
        user_id: this.user_id,
        content_title:this.contents,
      }).then((data) => {
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.record_show();
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
};
</script>

<style>
</style>